<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use think\Db;
use app\admin\model\Menu;

class MainController extends AdminBaseController
{

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     *  后台欢迎页
     */
    public function index()
    {
  
      $where['state']   = 1;
      $request = input('request.');
      $recentday = Db::connect('aizuoyou')
        ->name('coinrelease')
        ->field('releaseday')
        ->order('releaseday', 'DESC')
        ->find();
      
      if (!empty($request['releaseday'])) {
        /**获取最新数据日期 并比较判断*/
        $queryday = date('Ymd', strtotime($request['releaseday']));
        
        if ($queryday >=  $recentday['releaseday']) {
          $where['releaseday'] = $recentday['releaseday'];
        }
        else {
          $where['releaseday'] = $queryday;
        }
      }
      
      /**获取昨日平台数据一览**/
      $yesterday_data = Db::connect('aizuoyou')
        ->name('coinrelease')
        ->where($where)
        ->order('releaseday', 'DESC')
        ->find();
      
      if ($yesterday_data) {
        // 资金池新增资金
        $yesterday_data['increate_totalgameordermoney'] = ($yesterday_data['totalgameordermoney'] - $yesterday_data['totalgameorderreturnprofitmoney']) * 35 / 100;
  
        // 资金池增长比例
        $yesterday_data['increate_proportion_totalgameordermoney'] = ($yesterday_data['increate_totalgameordermoney'] / ($yesterday_data['initcashpool'] + $yesterday_data['totalgameorderreturnprofitmoney'] - $yesterday_data['totalexchangecash']));
  
        // 爱币池增长比例
        $yesterday_data['increate_proportion_totalgameordericon'] = $yesterday_data['increate_proportion_totalgameordermoney'] * 9 / 10;
  
        // 爱币池新增爱币
        $yesterday_data['increate_initcoinpool'] = ($yesterday_data['initcoinpool'] + $yesterday_data['totalgameorderreturnprofitcoin'] - $yesterday_data['totalexchangecoin']) * $yesterday_data['increate_proportion_totalgameordericon'];
  
        // 公司账户的收入
        $yesterday_data['company_account_income'] = ($yesterday_data['totalgameordermoney'] - $yesterday_data['totalgameorderreturnprofitmoney']) - $yesterday_data['increate_totalgameordermoney'];
  
        // 时间
        $yesterday_data['releaseday'] = date('Y-m-d',strtotime($yesterday_data['releaseday']));
      }
      
      $this->assign('yesterday_data', $yesterday_data);
      
        return $this->fetch();
    }
}
